package com.br4mmie.asciistory;

import com.br4mmie.asciistory.map.MapObject;

public class Camera 
{
	private int locX,locY;
	private int offsetX,offsetY;
	private boolean locked;
	private MapObject target;
	
	public Camera(int x, int y)
	{
		locX = x;
		locY = y;
		offsetX = offsetY = 0;
		locked = false;
		target = null;
	}
	
	public void setX(int x)
	{
		/**
		 * basic setter, sets locX
		 */
		locX = x;
	}
	
	public void setY(int y)
	{
		/**
		 * basic setter, sets locY
		 */
		locY = y;
	}
	
	public void setOffsetX(int x)
	{
		/**
		 * basic setter, sets offsetX
		 */
		offsetX = x;
	}
	
	public void setOffsetY(int y)
	{
	/**
	 * basic setter, sets offsetY
	 */
	offsetY = y;
	}
	
	
	public int getX()
	{
		/**
		 * basic getter returns locX
		 */
		return locX;
	}
	
	public int getY()
	{
		/**
		 * basic getter returns locY
		 */
		return locY;
	}
	
	public int getOffsetX()
	{
		/**
		 * basic getter returns offsetX
		 */
		return offsetX;
	}
	
	public int getOffsetY()
	{
		/**
		 * basic getter returns offsetY
		 */
		return offsetY;
	}
	
	public boolean isLocked()
	{
		/**
		 * basic getter returns locked
		 */
		return locked;
	}
	
	public MapObject getTarget()
	{
		/**
		 * basic getter returns target
		 */
		return target;
	}
	
	public void unlock()
	{
		/**
		 * unlock the camera's focus
		 */
		locked = false;
		target = null;
		offsetX = offsetY = 0;
	}
	
	public void lock(MapObject trgt)
	{
		/**
		 * lock the camera at the target
		 * camera remains centered on target until unlocked
		 */
		if(trgt == null)return;
		this.target = trgt;
		locX = trgt.getX();
		locY = trgt.getY();
		locked = true;
	}
	
	public void move(int dX, int dY)
	{
		/**
		 * move the camera the specified amount.
		 */
		
		locX += dX;
		locY += dY;
	}
	
	public void onLoop()
	{
		/**
		 * Basic functions to be executed every game loop.
		 */
		if(locked)//Update the Camera position if it has a target and is locked.
		{
			locX = target.getX()+offsetX;
			locY = target.getY()+offsetY;
		}
	}
		
}
